package com.dingwen.frame.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * knife4j 配置类
 *
 * @author dingwen
 * @date 2021.05.28 16:00
 *
 */
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class Knife4jAutoConfiguration {
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("# DINGWEN FRAME DOCS")
                        .description("# dingwen frame starter service APIs")
                        .termsOfServiceUrl("http://www.baidu.com")
                        .contact(new Contact("dingwen", "http:///www.dingwen.com", "1981723769@qq.com"))
                        .version("v1.0")
                        .build())
                //忽略生成主键的参数类型
                .ignoredParameterTypes(HttpSession.class, HttpServletResponse.class, HttpServletRequest.class)
                //分组名称
                .groupName("1.0")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com"))
                .paths(PathSelectors.any())
                .build();
    }
}
